﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jayden.Dll.Core.Persistence.Data.SQLite;
using Jayden.Dll.Core;
using Jayden.Dll.Core.Persistence;
using Jayden.Dll.Core.Persistence.Models;
using Jayden.Dll.Core.Persistence.Data;
using System.Data.Common;

namespace Jayden.Dll.Entities.Common
{
	public class SQLiteInvoiceLineDataAccess : SQLiteDataAccess<InvoiceLine>, InvoiceLineDataAccess
	{
		public SQLiteInvoiceLineDataAccess(Configuration config, UnitOfWork uow, Entity entity) : base(config, uow, entity) { }

		public List<InvoiceLine> ReadByInvoiceId(long invoiceId)
		{
			string clauseString = "InvoiceId=@InvoiceId";

			string selectCommandText = Helper.GenerateSelect(null, Entity.Table.TableName, clauseString, null, new string[] { "LineIndex" }, null, null);
			using (DbCommandProxy selectCommand = CreateCommand(selectCommandText))
			{
				CreateParameter(selectCommand, "InvoiceId", invoiceId);
				using (DbDataReader reader = selectCommand.Command.ExecuteReader())
				{
					List<InvoiceLine> lines = new List<InvoiceLine>(EnumerateFromReader(reader));
					return lines;
				}
			}
		}


	}
}
